/**
 * QueuePopupMenu.java
 * @author Daniel Liu
 * Create: 2007-1-4 ����09:22:38
 */
package org.lex.ftp.ui.queue;

import java.awt.Component;
import javax.swing.*;

import org.lex.ftp.FTP;
import org.lex.ftp.ui.queue.actions.*;
import org.lex.ftp.util.Actions;

public class QueuePopupMenu extends JPopupMenu {
	private static final String SaveQueueAC = "Save Queue...";
	private static final String LoadQueueAC = "Load Queue...";
	private final FTP app;
	// --------------------
	private Action transfer = null;
	private Action edit = null;
	private Action remove = null;
	private Action moveTop = null;
	private Action moveUp = null;
	private Action moveDown = null;
	private Action moveBottom = null;
	private Action queueInfo = null;
	private Action saveQueue = null;
	private Action loadQueue = null;
	private Action clearQueue = null;

	public QueuePopupMenu(FTP app) {
		super();
		this.app = app;
		initialize();
	}

	public void show(Component invoker, int x, int y) {
		super.show(invoker, x, y);
	}

	private void initialize() {
		this.initializeActions();
		// -----------------------
		this.add(transfer);
		this.addSeparator();
		// -----------------------
		this.add(edit);
		this.add(remove);
		JMenu move = new JMenu("Move");
		move.add(this.moveTop);
		move.add(this.moveUp);
		move.add(this.moveDown);
		move.add(this.moveBottom);
		this.add(move);
		this.addSeparator();
		// ------------------------
		this.add(this.queueInfo);
		this.addMenuItem(SaveQueueAC);
		this.addMenuItem(LoadQueueAC);
		this.addSeparator();
		this.add(clearQueue);
	}

	private void initializeActions() {
		ActionMap am = app.getActionMap();
		this.transfer = am.get(Actions.TRANSFER);
		this.edit = new EditAction(app);
		this.remove = new RemoveAction(app);
		this.moveTop = new MoveTopAction(app);
		this.moveUp = new MoveUpAction(app);
		this.moveDown = new MoveDownAction(app);
		this.moveBottom = new MoveBottomAction(app);
		this.queueInfo = new QueueInfoAction(app);
		// ----------------------------------------
		this.clearQueue = new ClearQueueAction(app);
	}

	private void addMenuItem(String ac) {
		this.add(this.createMenuItem(ac));
	}

	private JMenuItem createMenuItem(String ac) {
		JMenuItem menuItem = new JMenuItem();
		menuItem.setText(ac);
		menuItem.setActionCommand(ac);
		return menuItem;
	}
}
